home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.06 Jun 95 / Apple Events in PowerPlant / Powering Up Code / SCPage.cp < prev    next >
Encoding:
Text File  |  1995-04-05  |  2.2 KB  |  107 lines  |  [TEXT/MMCC]

  1. // ===========================================================================
  2. // SCPage.cp -- the page class 
  3. // ===========================================================================
  4. // © 1995 James Kaput, Jeremy Roschelle SimCalc Project
  5.  
  6. #include "SCPage.h"
  7. #include "SCDoc.h"
  8. #include "SCApp.h"
  9. #include "SCModelProperty.h"
  10.  
  11. SCPage::SCPage(SCDoc *inDoc)
  12. {
  13.     mSuperModel = inDoc;
  14.     inDoc->AddSubModel(this); // stores the page a list in the document
  15.     mID = SCApp::GenerateUniqueID();
  16.     *mName = 0;
  17. }
  18.  
  19. SCPage::~SCPage()
  20. {
  21.     mSuperModel->RemoveSubModel(this);
  22.     mSuperModel = nil; // prevents LModelObject from doing removal
  23. }
  24.  
  25. void    
  26. SCPage::GetDescriptor(Str255 outName) const
  27. {
  28.     CopyPStr(mName,outName);
  29. }
  30.  
  31. Int32     
  32. SCPage::GetID() const
  33. {
  34.     return mID;
  35. }
  36.  
  37. LModelProperty*    
  38. SCPage::GetModelProperty(DescType inProperty)
  39. {
  40.     return new SCModelProperty(inProperty, this);
  41. }
  42.  
  43. void    
  44. SCPage::HandleAppleEvent(const AppleEvent    &inAppleEvent,
  45.                     AppleEvent            &outAEReply,
  46.                     AEDesc                &outResult,
  47.                     Int32                inAENumber)
  48. {
  49.     switch (inAENumber) {
  50.         case ae_Select:
  51.             ((SCDoc *)mSuperModel)->SetSelection(this);
  52.             break;
  53.         default:
  54.             inherited::HandleAppleEvent(inAppleEvent,outAEReply,outResult,inAENumber);
  55.     }
  56. }
  57.  
  58. void    
  59. SCPage::GetAEProperty(
  60.                     DescType        inProperty,
  61.                     const AEDesc    &inRequestedType,
  62.                     AEDesc            &outPropertyDesc) const
  63. {
  64.     long        id, index;
  65.     Str255    name;
  66.     
  67.     switch (inProperty) {
  68.         case pIndex:
  69.             index = mSuperModel->GetPositionOfSubModel(SCPage::modelKind, this); 
  70.             FailOSErr_(AECreateDesc(typeLongInteger, (Ptr) &index,
  71.                         sizeof(long), &outPropertyDesc));
  72.             break;
  73.         case 'ID  ':
  74.             id = GetID();
  75.             FailOSErr_(AECreateDesc(typeLongInteger, (Ptr) &id,
  76.                         sizeof(long), &outPropertyDesc));
  77.             break;
  78.         case pName:
  79.             GetDescriptor(name);
  80.             FailOSErr_(AECreateDesc(typeChar, &(name[1]),
  81.                         name[0], &outPropertyDesc));
  82.             break;
  83.         default:
  84.             inherited::GetAEProperty(inProperty,inRequestedType,outPropertyDesc);
  85.     }
  86.  
  87. }
  88.  
  89. void    
  90. SCPage::SetAEProperty(
  91.                     DescType        inProperty,
  92.                     const AEDesc    &inValue,
  93.                     AEDesc        &outAEReply)
  94. {
  95.     Str255    name;
  96.     
  97.     switch (inProperty) {            
  98.         case pName:
  99.             UExtractFromAEDesc::ThePString(inValue,name);
  100.             CopyPStr(name,mName);
  101.             break;
  102.         default:
  103.             inherited::SetAEProperty(inProperty,inValue,outAEReply);
  104.     }
  105.  
  106. }
  107.